interface State {
    doAction(context: Context): void;
}

class StartState implements State {
    public doAction(context: Context): void {
        console.log("Player is in start state");
        context.setState(this);
    }
    public toString(): string {
        return 'Start State';
    }
}

class StopState implements State {
    public doAction(context: Context): void {
        console.log("Player is in stop state");
        context.setState(this);
    }
    public toString(): string {
        return 'Stop State';
    }
}

class Context {
    private state: State | null;
    public constructor() {
        this.state = null;
    }
    public setState(state: State): void {
        this.state = state;
    }
    public getState(): State | null {
        return this.state;
    }
}

function main() {
    const context: Context = new Context();
    const startState: StartState = new StartState();
    startState.doAction(context);
    console.log(context.getState()?.toString());
    const stopState: StopState = new StopState();
    stopState.doAction(context);
    console.log(context.getState()?.toString());
}

main();
